package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAfterServiceType;
import com.ruoyi.zsyh.service.IZsyhAfterServiceTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 售后工单服务分类Controller
 * 
 * @author yuexl
 * @date 2022-09-01
 */
@Controller
@RequestMapping("/zsyh/afterServiceType")
public class ZsyhAfterServiceTypeController extends BaseController
{
    private String prefix = "zsyh/afterServiceType";

    @Autowired
    private IZsyhAfterServiceTypeService zsyhAfterServiceTypeService;

    @RequiresPermissions("zsyh:afterServiceType:view")
    @GetMapping()
    public String afterServiceType()
    {
        return prefix + "/afterServiceType";
    }

    /**
     * 查询售后工单服务分类树列表
     */
    @RequiresPermissions("zsyh:afterServiceType:list")
    @PostMapping("/list")
    @ResponseBody
    public List<ZsyhAfterServiceType> list(ZsyhAfterServiceType zsyhAfterServiceType)
    {
        List<ZsyhAfterServiceType> list = zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeList(zsyhAfterServiceType);
        return list;
    }

    /**
     * 导出售后工单服务分类列表
     */
    @RequiresPermissions("zsyh:afterServiceType:export")
    @Log(title = "售后工单服务分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAfterServiceType zsyhAfterServiceType)
    {
        List<ZsyhAfterServiceType> list = zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeList(zsyhAfterServiceType);
        ExcelUtil<ZsyhAfterServiceType> util = new ExcelUtil<ZsyhAfterServiceType>(ZsyhAfterServiceType.class);
        return util.exportExcel(list, "售后工单服务分类数据");
    }

    /**
     * 新增售后工单服务分类
     */
    @GetMapping(value = { "/add/{id}", "/add/" })
    public String add(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("zsyhAfterServiceType", zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeById(id.toString()));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存售后工单服务分类
     */
    @RequiresPermissions("zsyh:afterServiceType:add")
    @Log(title = "售后工单服务分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAfterServiceType zsyhAfterServiceType)
    {
        return toAjax(zsyhAfterServiceTypeService.insertZsyhAfterServiceType(zsyhAfterServiceType));
    }

    /**
     * 修改售后工单服务分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAfterServiceType zsyhAfterServiceType = zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeById(id);
        mmap.put("zsyhAfterServiceType", zsyhAfterServiceType);
        return prefix + "/edit";
    }

    /**
     * 修改保存售后工单服务分类
     */
    @RequiresPermissions("zsyh:afterServiceType:edit")
    @Log(title = "售后工单服务分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAfterServiceType zsyhAfterServiceType)
    {
        return toAjax(zsyhAfterServiceTypeService.updateZsyhAfterServiceType(zsyhAfterServiceType));
    }

    /**
     * 修改保存售后工单服务分类
     */
    @Log(title = "售后工单服务分类", businessType = BusinessType.UPDATE)
    @PostMapping("/getAllType/{parentId}")
    @ResponseBody
    public AjaxResult getAllType(@PathVariable("parentId") String parentId)
    {

        return new AjaxResult(AjaxResult.Type.SUCCESS,"success",zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeById(parentId).getServiceName().toString());
    }

    /**
     * 删除
     */
    @RequiresPermissions("zsyh:afterServiceType:remove")
    @Log(title = "售后工单服务分类", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("id") String id)
    {
        return toAjax(zsyhAfterServiceTypeService.deleteZsyhAfterServiceTypeById(id));
    }

    /**
     * 选择售后工单服务分类树
     */
    @GetMapping(value = { "/selectAfterServiceTypeTree/{id}", "/selectAfterServiceTypeTree/" })
    public String selectAfterServiceTypeTree(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("zsyhAfterServiceType", zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeById(id.toString()));
        }
        return prefix + "/tree";
    }

    /**
     * 添加下单是产品费用，选择服务分类
     */
    @GetMapping(value = { "/selectAfterServiceTypeTree1/{id}", "/selectAfterServiceTypeTree1/" })
    public String selectAfterServiceTypeTree1(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("zsyhAfterServiceType", zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeById(id.toString()));
        }
        return prefix + "/tree1";
    }

    /**
     * 加载售后工单服务分类树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = zsyhAfterServiceTypeService.selectZsyhAfterServiceTypeTree();
        return ztrees;
    }
}
